package com.qmx.qmxapp.adapter;


import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseSectionMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.qmx.qmxapp.R;
import com.qmx.qmxapp.base.BaseApplication;
import com.qmx.qmxapp.bean.MultipleItem;
import com.qmx.qmxapp.constant.AppConstant;
import com.qmx.qmxapp.data.SectionMultipleItem;
//import com.qmx.qmxapp.bean.SectionMultipleItem;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * @author chengxiangtong
 * @date 2018/11/6
 * version : 1.0
 * class describe：*
 */
public class ContactMultipleItemAdapter extends BaseSectionMultiItemQuickAdapter<SectionMultipleItem, BaseViewHolder> {
    /**
     * init ContactMultipleItemAdapter
     * 1. add your header resource layout
     * 2. add some kind of items
     *
     * @param sectionHeadResId The section head layout id for each item
     * @param data             A new list is created out of this one to avoid mutable list
     */
    public ContactMultipleItemAdapter(int sectionHeadResId, List data) {
        super(sectionHeadResId, data);
        addItemType(SectionMultipleItem.TEXT, R.layout.layout_contacts_item);
        addItemType(SectionMultipleItem.IMG_TEXT, R.layout.layout_contacts_item_noarrow);
    }

    @Override
    protected void convertHead(BaseViewHolder helper, final SectionMultipleItem item) {
        // deal with header viewHolder
        helper.setText(R.id.header, item.header);
        helper.setVisible(R.id.more, item.isMore());
        helper.addOnClickListener(R.id.more);
    }

    @Override
    protected void convert(BaseViewHolder helper, SectionMultipleItem item) {
        // deal with multiple type items viewHolder
        helper.addOnClickListener(R.id.card_view);
        switch (helper.getItemViewType()) {
            case MultipleItem.TEXT:
                switch (item.getVideo().getImg()) {
                    case "department":
                        helper.setImageResource(R.id.ci_head_icon, R.drawable.icon_group_department);
                        break;
                    case "discuss":
                        helper.setImageResource(R.id.ci_head_icon, R.drawable.icon_group_discuss);
                        break;
                }
                helper.setText(R.id.item_text_user_name, item.getVideo().getName());
                break;
            case MultipleItem.IMG_TEXT:
                if (item.getVideo().getImg().contains("http")) {
                    Glide.with(BaseApplication.getInstance()).load(item.getVideo().getImg())
                            //                        .error(R.drawable.beauty)
                            .into((CircleImageView) helper.getView(R.id.ci_head_icon));
                } else {
                    Glide.with(BaseApplication.getInstance()).load(AppConstant.Url + item.getVideo().getImg())
                            //                        .error(R.drawable.beauty)
                            .into((CircleImageView) helper.getView(R.id.ci_head_icon));
                }

                break;
        }
    }
}
